package com.tjsinfo.tjsoa.system.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
/**
 * 修改用户
 * @author Administrator
 *
 */
public class AlterUserAction extends Action{
	private ISystemUserBo systemUserBo;

	public ISystemUserBo getSystemUserBo() {
		return systemUserBo;
	}

	public void setSystemUserBo(ISystemUserBo systemUserBo) {
		this.systemUserBo = systemUserBo;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		try {
			Integer userid = Integer.parseInt(request.getParameter("userid"));
			TSystemUser systemUser = systemUserBo.findByIdSystemUser(userid);
			if (request.getParameter("userdatabaseId") != null && Integer.parseInt(request.getParameter("userdatabaseId"))  != 0) {
				Integer dataBaseId = Integer.parseInt(request.getParameter("userdatabaseId"));
				systemUser.setDataBaseId(dataBaseId);
			}
			if (request.getParameter("erjigongsiid") != null && !"null".equals(request.getParameter("erjigongsiid")  ) ) {
				Integer erjigongsiid = Integer.parseInt(request.getParameter("erjigongsiid"));
				systemUser.setSubUserId(erjigongsiid);
			}
			String loginname = request.getParameter("loginname");
			String username = request.getParameter("username");
			Integer orderNo =  Integer.parseInt(request.getParameter("orderNo")); 
			String email = request.getParameter("email")==null?null:request.getParameter("email");
			String departmentid = request.getParameter("departmentid"); 
			String dutyid = request.getParameter("dutyid");
			String postid = request.getParameter("postid")==null?null:request.getParameter("postid");
			String rloesGroupid = request.getParameter("rolesgroupid"); 
			String rolesid  = request.getParameter("rolesid");
			Integer ischang = Integer.parseInt(request.getParameter("ischang"));
			systemUser.setLoginName(loginname);
			systemUser.setUserName(username);
			systemUser.setEmail(email);
			Byte state = 0;
			systemUser.setState(state);
			systemUser.setOrderNo(orderNo);
			systemUserBo.alterSystemUser(systemUser, departmentid, dutyid, postid, rloesGroupid, rolesid,ischang);
			
			String type = String.valueOf(request.getParameter("type"));
			String roleRroupId = String.valueOf(request.getParameter("id"));
			String linkurl="";
			if(type.equals("1")){
				linkurl = "tjsinfo/tjsoa/system/rolegroupuserlist.do?id="+roleRroupId;
			}else{
				linkurl = "system/user/userlist.jsp?fanhui=true";
			}
			request.setAttribute("fanhui", "true");
			request.setAttribute("linkurl", linkurl);
			request.setAttribute("message", "system.userUpdate.message");
			return mapping.findForward("success");
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			request.setAttribute("Exception", e);
			return mapping.findForward("failed");
		}
		
	}
	
}
